package com.example.concurrent.demo.atomic;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author susc
 * @title: AtomicIntegerTest
 * @projectName concurrent-demo
 * @description: TODO
 * @date 2021/9/2815:11
 */
public class AtomicIntegerTest {
    private volatile int count = 0;
    // 若要线程安全执行执行count++,需要加锁

    private volatile AtomicInteger countAtomic = new AtomicInteger(0);

    public synchronized void increment() {
        count++;
    }

    public int getCount(){
        return count;
    }

    public void incrementAtomic(){
        countAtomic.incrementAndGet();
    }

    public int getCountAtomic(){
        return countAtomic.get();
    }
    
}
